﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace HangameAuto01
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ThreadStart threadStart = delegate()
            {
                screenCapture(false);
            };   
        }

        public void screenCapture(bool showCursor)
        {



            this.timer1.Start();


        }

        public void CaptureImage(bool showCursor, Size curSize, Point curPos, Point SourcePoint, Point DestinationPoint, Rectangle SelectionRectangle)
        {

            using (Bitmap bitmap = new Bitmap(SelectionRectangle.Width, SelectionRectangle.Height))
            {

                using (Graphics g = Graphics.FromImage(bitmap))
                {

                    g.CopyFromScreen(SourcePoint, DestinationPoint, SelectionRectangle.Size);

                    if (showCursor)
                    {

                        Rectangle cursorBounds = new Rectangle(curPos, curSize);
                        Cursors.Default.Draw(g, cursorBounds);

                    }
                    Image img = (Image)bitmap;
                    Clipboard.SetImage(img);
                    this.pictureBox1.Image= Clipboard.GetImage();


                }


                

            }

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Thread oThread = new Thread();
            oThread.Start();

            Point curPos = new Point(Cursor.Position.X, Cursor.Position.Y);
            Size curSize = new Size();
            curSize.Height = Cursor.Current.Size.Height;
            curSize.Width = Cursor.Current.Size.Width;

            this.TopMost = false;

            System.Threading.Thread.Sleep(250);

            Rectangle bounds = Screen.GetBounds(Screen.GetBounds(Point.Empty));
            string fi = "";
            this.pictureBox1.InitialImage = null;
            CaptureImage(false, curSize, curPos, Point.Empty, Point.Empty, bounds);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.timer1.Stop();
        }




    }
}
